﻿package {
   import flash.display.Shape;
   import flash.events.Event;
   import flash.filters.BlurFilter;
   import flash.display.MovieClip;

   public class Meteor extends MovieClip {
      private var stageWidth:int = 600;
      private var stageHeight:int = 800;
      private var highestDropSpeed:uint = 30;
      private var dropSpeed:int = Math.round(Math.random() * Math.random() * highestDropSpeed);
      private var incrementer:int = Math.round(Math.random() * 100);
      private var shades:Array = [ 0xFFFFFF, 0xCCCCCC, 0x999999, 0x666666 ];
      private var windSpeed:int = 22;
      
      public function Meteor() {
         graphics.beginFill(shades[ Math.ceil(Math.random() * shades.length) ]);
         graphics.drawCircle(0,0,4);
         graphics.endFill();
         
         filters = [ new BlurFilter(1,dropSpeed,1) ];
         addEventListener(Event.ENTER_FRAME,update); 
         reset();
      }
      private function reset():void {
         y = Math.random() * stageHeight * -1;
         x = Math.random() * stageWidth - (windSpeed*100);
         scaleX = scaleY = 0.25 + (Math.random() * Math.random() * 0.75);
      }
      private function update(e:Event):void {
         y += dropSpeed;
         x += windSpeed + Math.sin(incrementer/10) * (1/(dropSpeed/3));
         if (y > stageHeight) {
            reset();
         }
         incrementer++;
      }
   }
}

